const r = require('readline');

const rl = r.createInterface({
  input: process.stdin,
  output: process.stdout
});

function calculate(num1, num2, operator) {
  switch (operator) {
    case '+':
      return num1 + num2;
    case '-':
      return num1 - num2;
    case '*':
      return num1 * num2;
    case '/':
      if (num2 === 0) {
        return 'num2不能为0';
      }
      return num1 / num2;
    default:
      return '错误';
  }
}

rl.question('请输入第一个数字: ', (a) => {
  const num1 = parseFloat(a);
  rl.question('请输入第二个数字: ', (b) => {
    const num2 = parseFloat(b);
    rl.question('请输入运算符 (+, -, *, /): ', (operator) => {
      const result = calculate(num1, num2, operator);
      console.log(`计算结果: ${result}`);
      rl.close();
    });
  });
});
